class "Vector2"

function Vector2:constructor(x, y)
	self.x = x or 0
	self.y = y or 0
	--[[
	local mt = getmetatable(self)
	mt.__index = 
		function(this, field)
			if(field == "width")then
				return this.x
			elseif(field == "height")then
				return this.y
			elseif(field == "xy")then
				return this
			elseif(field == "yx")then
				return Vector2(this.y, this.x)
			end
		end
		
	mt.__newindex = 
		function(this, field, value)
			if(field == "width")then
				this.x = value
			elseif(field == "height")then
				this.y = value
			elseif(field == "xy")then
				this = value
			elseif(field == "yx")then
				this = Vector2(value.y, value.x)
			end
		end
	--]]
end

function Vector2:getLength()
	return math.sqrt(self.x*self.x + self.y*self.y)
end

function Vector2:normalize()
	local length = self:getLength()
	self.x = self.x / length
	self.y = self.y / length
end

class "Vector3"

function Vector3:constructor(x, y, z)
	self.x = x or 0
	self.y = y or 0
	self.z = z or 0
	--[[
	local mt = getmetatable(self)
	mt.__index = 
		function(this, field)
			if(field == "width")then
				return this.x
			elseif(field == "height")then
				return this.y
			elseif(field == "depth")then
				return this.z
			elseif(field == "xy")then
				return Vector2(this.x, this.y)
			elseif(field == "yx")then
				return Vector2(this.y, this.x)
			elseif(field == "yz")then
				return Vector2(this.y, this.z)
			elseif(field == "zy")then
				return Vector2(this.z, this.y)
			elseif(field == "xz")then
				return Vector2(this.x, this.z)
			elseif(field == "zx")then
				return Vector2(this.z, this.x)
			elseif(field == "xyz")then
				return this
			elseif(field == "xzy")then
				return Vector3(this.x, this.z, this.y)
			elseif(field == "zxy")then
				return Vector3(this.z, this.x, this.y)
			elseif(field == "yxz")then
				return Vector3(this.y, this.x, this.z)
			elseif(field == "yzx")then
				return Vector3(this.y, this.z, this.x)
			end
		end
		
	mt.__newindex = 
		function(this, field, value)
			if(field == "width")then
				this.x = value
			elseif(field == "height")then
				this.y = value
			elseif(field == "depth")then
				this.z = value
			elseif(field == "xy")then
				this = Vector2(value.x, value.y, 0.0)
			elseif(field == "yx")then
				this = Vector2(value.y, value.x, 0.0)
			elseif(field == "yz")then
				this = Vector2(value.y, value.z, 0.0)
			elseif(field == "zy")then
				this = Vector2(value.z, value.y, 0.0)
			elseif(field == "xz")then
				this = Vector2(value.x, value.z, 0.0)
			elseif(field == "zx")then
				this = Vector2(value.z, value.x, 0.0)
			elseif(field == "xyz")then
				this = value
			elseif(field == "xzy")then
				this = Vector3(value.x, value.z, value.y)
			elseif(field == "zxy")then
				this = Vector3(value.z, value.x, value.y)
			elseif(field == "yxz")then
				this = Vector3(value.y, value.x, value.z)
			elseif(field == "yzx")then
				this = Vector3(value.y, value.z, value.x)
			end
		end
	--]]
end

function Vector3:getLength()
	return math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z)
end

function Vector3:normalize()
	local length = self:getLength()
	self.x = self.x / length
	self.y = self.y / length
	self.z = self.z / length
end